package weather.newer.com.juheweather;

import android.content.Context;
import android.widget.TextView;

import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.Entry;

public class MyMarkerView extends MarkerView {
    private TextView tvContent;

    public MyMarkerView(Context context, int layoutResource) {
        super(context, layoutResource);
        tvContent = (TextView) findViewById(R.id.tvContent);
    }

    // callbacks everytime the MarkerView is redrawn, can be used to update the
    // content
    @Override
    public void refreshContent(Entry e, int dataSetIndex) {
        if (e instanceof CandleEntry) {
            CandleEntry ce = (CandleEntry) e;
            tvContent.setText("" + ce.getHigh());//值为浮点数
            //tvContent.setText("" + Utils.formatNumber(ce.getHigh(), 0, true));//值为四舍五入后的整数
        } else {
            tvContent.setText("" + e.getVal());//值为浮点数
            //tvContent.setText("" + Utils.formatNumber(e.getVal(), 0, true));//值为四舍五入后的整数
        }
    }

    @Override
    public int getXOffset() {
        //设置偏移量
        if (MyLineChartActivity.ChartClickPosition <= 3) {//避免数值与纵坐标重叠

            return 0;

        } else {

            return -getMeasuredWidth();
        }
    }

    @Override
    public int getYOffset() {//设置偏移量

        if (MyLineChartActivity.ChartClickPosition <= 3) {//避免数值与横坐标重叠
            return 0;
        } else {
            return -getMeasuredHeight();
        }
    }
}